import 'package:flutter/material.dart';

class CommonFormItem extends StatelessWidget {
  const CommonFormItem(
      {Key key,
      this.label,
      this.contentBuilder,
      this.suffix,
      this.suffixText,
      this.hintText,
      this.onChanged,
      this.controller,
      this.textDirection,
      this.textAlign})
      : super(key: key);
  final String label;
  final Widget Function(BuildContext context) contentBuilder;

  final Widget suffix;
  final String suffixText;

  final String hintText;
  final ValueChanged onChanged;
  final TextEditingController controller;

  final TextDirection textDirection;
  final TextAlign textAlign;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 14),
      decoration: BoxDecoration(
          border: Border(
              bottom:
                  BorderSide(width: 1, color: Theme.of(context).dividerColor))),
      child: Row(
        children: [
          Container(
            width: 100,
            child: Text(
              label,
              style: TextStyle(fontSize: 16),
            ),
          ),
          Expanded(
            child: contentBuilder != null
                ? contentBuilder(context)
                : TextField(
                    textAlign: textAlign ?? TextAlign.start,
                    textDirection: textDirection,
                    controller: controller,
                    decoration: InputDecoration(
                        hintText: hintText, border: InputBorder.none),
                  ),
          ),
          if (suffix != null) suffix,
          if (suffix == null && suffixText != null)
            Text(
              suffixText,
              style: TextStyle(fontSize: 16),
            )
        ],
      ),
    );
  }
}
